﻿using EasyAbp.Abp.Aliyun.Common.Configurations;
using EasyAbp.Abp.Aliyun.Sms;
using EasyAbp.Abp.PhoneNumberLogin.Provider.Aliyun.Localization;
using Microsoft.Extensions.Options;
using Volo.Abp.Localization;
using Volo.Abp.Settings;

namespace EasyAbp.Abp.PhoneNumberLogin.Provider.Aliyun.Settings
{
    public class PhoneNumberLoginProviderAliyunSettingDefinitionProvider : SettingDefinitionProvider
    {
        private readonly PhoneNumberLoginProviderAliyunOptions _phoneNumberLoginProviderAliyunOptions;
        private readonly AbpAliyunOptions _commonOptions;
        private readonly AbpAliyunSmsOptions _smsOptions;

        public PhoneNumberLoginProviderAliyunSettingDefinitionProvider(
            IOptions<PhoneNumberLoginProviderAliyunOptions> phoneNumberLoginProviderAliyunOptions,
            IOptions<AbpAliyunOptions> commonOptions,
            IOptions<AbpAliyunSmsOptions> smsOptions)
        {
            _phoneNumberLoginProviderAliyunOptions = phoneNumberLoginProviderAliyunOptions.Value;
            _commonOptions = commonOptions.Value;
            _smsOptions = smsOptions.Value;
        }

        public override void Define(ISettingDefinitionContext context)
        {
            //Define your own settings here. Example:
            //context.Add(new SettingDefinition(DenturePlusSettings.MySetting1));
            //context.Add(new SettingDefinition(
            //    PhoneNumberLoginProviderAliyunSettings.EndPoint,
            //    _smsOptions.EndPoint,
            //    L("EndPoint")));

            context.Add(new SettingDefinition(
                PhoneNumberLoginProviderAliyunSettings.EndPoint));

            context.Add(new SettingDefinition(
              PhoneNumberLoginProviderAliyunSettings.DefaultSignName));

            context.Add(new SettingDefinition(
                PhoneNumberLoginProviderAliyunSettings.LoginTemplateCode,
                _phoneNumberLoginProviderAliyunOptions.LoginTemplateCode,
                L("LoginTemplateCode")));

            context.Add(new SettingDefinition(
                PhoneNumberLoginProviderAliyunSettings.RegisterTemplateCode,
                _phoneNumberLoginProviderAliyunOptions.RegisterTemplateCode,
                L("RegisterTemplateCode")));

            context.Add(new SettingDefinition(
                PhoneNumberLoginProviderAliyunSettings.ConfirmTemplateCode,
                _phoneNumberLoginProviderAliyunOptions.ConfirmTemplateCode,
                L("ConfirmTemplateCode")));

            context.Add(new SettingDefinition(
                PhoneNumberLoginProviderAliyunSettings.ResetPasswordTemplateCode,
                _phoneNumberLoginProviderAliyunOptions.ResetPasswordTemplateCode,
                L("ResetPasswordTemplateCode")));

        }

        private static LocalizableString L(string name)
        {
            return LocalizableString.Create<PhoneNumberLoginProviderAliyunResource>(name);
        }
    }
}